<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>api-demo</title>
    <script src="lib/include.js"></script>
</head>
<body>
    <div id="app" v-cloak>
        <button type="button" class="btn btn-info" @click="get(0)" v-if="permission(0)" >Get请求测试</button>
        <button type="button" class="btn btn-info" @click="post(1)" v-if="permission(1)" >Post请求测试</button>
        <button type="button" class="btn btn-info" @click="put(2)" v-if="permission(2)" >Put请求测试</button>
    </div>

    <script>
        /**
         * Created by zhoulin on 2018/6/25.
         */

        var app = new Vue({
            el: '#app',
            data: {
                dataList: {},//所有数据
                checkindex:0,//头部按钮切换标识 Ordinary member
                permissions:['get','post','put'],//权限数组

            },
            //进入页面初始化方法
            created: function () {
                var that = this;

            },
            methods: {
                permission: function (index) {
                    var str = ['get','post','put'];
                    console.log(str.indexOf(this.permissions[index]) != -1 );  // true
                    return (str.indexOf(this.permissions[index]) != -1);
                },
                get:function (index) {
                    var that = this;
                    Get(that,_HOST+_API.admin_index_getInfoById+"1",that.permissions[index])
                        .then(function (response) {
                        // 响应成功回调
                        console.log(response)
                        if(response){
                            if(response.success){
                                layer.msg("查询成功！");
                            }else {
                                layer.msg(response.msg, {time: 1500, icon:5});
                            }
                        }
                    })
                },
                post:function (index) {
                    var that = this;
                    var param = {
                        username:"admin",
                        password:"admin"
                    };
                    Post(that,_HOST+_API.admin_index_doLogin,param,true)
                        .then(function (response) {
                        // 响应成功回调
                        console.log(response)
                        if(response){
                            if(response.success){
                                layer.msg(response.msg, {time: 1500, icon:1});
                            }else {
                                layer.msg(response.msg, {time: 1500, icon:5});
                            }
                        }
                    })
                },
                put:function (index) {
                    var that = this;

                    var param = {
                        "id": 1,
                        "username": "admin",
                        "nickname": "平台超级管理员",
                        "password": "5924a44bffee4d1f2975bec9a6ab6783",
                        "salt": "1522430063842",
                        "wxTel": "15084310042",
                        "tel": "15084310042",
                        "email": "1522430063842@qq.com",
                        "status": 1,
                        "gmtCreate": 1505266818000,
                        "gmtModified": 1553689745000,
                        "type": 0,
                        "loginId": 1,
                        "companyId": 0,
                        "version": 0,
                        "isDelete": 0
                    };
                    Put(that,_HOST+_API.admin_sysAdmin_update,param,true,that.permissions[index])
                        .then(function (response) {
                        // 响应成功回调
                        console.log(response)
                        if(response){
                            if(response.success){
                                layer.msg(response.msg, {time: 1500, icon:1});
                            }else {
                                layer.msg(response.msg, {time: 1500, icon:5});
                            }
                        }
                    })
                }
            }

        })

    </script>
</body>
</html>